package com.ruoyi.docdraw.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.docdraw.domain.SysSubProject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.docdraw.mapper.SysSubProjectFolderMapper;
import com.ruoyi.docdraw.domain.SysSubProjectFolder;
import com.ruoyi.docdraw.service.ISysSubProjectFolderService;

/**
 * 子项目文件夹Service业务层处理
 * 
 * @author lvtian
 * @date 2025-04-14
 */
@Service
public class SysSubProjectFolderServiceImpl implements ISysSubProjectFolderService 
{
    @Autowired
    private SysSubProjectFolderMapper sysSubProjectFolderMapper;

    /**
     * 查询子项目文件夹
     * 
     * @param subFolderId 子项目文件夹主键
     * @return 子项目文件夹
     */
    @Override
    public SysSubProjectFolder selectSysSubProjectFolderBySubFolderId(Long subFolderId)
    {
        return sysSubProjectFolderMapper.selectSysSubProjectFolderBySubFolderId(subFolderId);
    }

    /**
     * 查询子项目文件夹列表
     * 
     * @param sysSubProjectFolder 子项目文件夹
     * @return 子项目文件夹
     */
    @Override
    public List<SysSubProjectFolder> selectSysSubProjectFolderList(SysSubProjectFolder sysSubProjectFolder)
    {
        return sysSubProjectFolderMapper.selectSysSubProjectFolderList(sysSubProjectFolder);
    }

    /**
     * 新增子项目文件夹
     * 
     * @param sysSubProjectFolder 子项目文件夹
     * @return 结果
     */
    @Override
    public int insertSysSubProjectFolder(SysSubProjectFolder sysSubProjectFolder)
    {
        sysSubProjectFolder.setCreateTime(DateUtils.getNowDate());
        return sysSubProjectFolderMapper.insertSysSubProjectFolder(sysSubProjectFolder);
    }

    /**
     * 修改子项目文件夹
     * 
     * @param sysSubProjectFolder 子项目文件夹
     * @return 结果
     */
    @Override
    public int updateSysSubProjectFolder(SysSubProjectFolder sysSubProjectFolder)
    {
        sysSubProjectFolder.setUpdateTime(DateUtils.getNowDate());
        return sysSubProjectFolderMapper.updateSysSubProjectFolder(sysSubProjectFolder);
    }

    /**
     * 批量删除子项目文件夹
     * 
     * @param subFolderIds 需要删除的子项目文件夹主键
     * @return 结果
     */
    @Override
    public int deleteSysSubProjectFolderBySubFolderIds(Long[] subFolderIds)
    {
        return sysSubProjectFolderMapper.deleteSysSubProjectFolderBySubFolderIds(subFolderIds);
    }

    /**
     * 删除子项目文件夹信息
     * 
     * @param subFolderId 子项目文件夹主键
     * @return 结果
     */
    @Override
    public int deleteSysSubProjectFolderBySubFolderId(Long subFolderId)
    {
        return sysSubProjectFolderMapper.deleteSysSubProjectFolderBySubFolderId(subFolderId);
    }


    /**
     * 检查子项目下文件夹名称是否重复
     * @param sysSubProjectFolder
     * @return
     */
    @Override
    public boolean checkSubProjectFolderNameUnique(SysSubProjectFolder sysSubProjectFolder) {
        Long subFolderId = StringUtils.isNull(sysSubProjectFolder.getSubFolderId()) ? -1L : sysSubProjectFolder.getSubFolderId();
        SysSubProjectFolder info = sysSubProjectFolderMapper.checkSubProjectFolderNameUnique(sysSubProjectFolder.getSubFolderName(), sysSubProjectFolder.getSubProjectId());
        if (StringUtils.isNotNull(info) && info.getSubFolderId().longValue() != subFolderId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
